<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$item=$this->plugin_setting('setting');
$return['adv']=$item['hdps'];
if($_RQ['op']=='main'){
	$return['group']=pdo_getall('jy_cmso2o_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'','','paixu desc');
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$postdata=get_postdata();
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
    $fields=array('id','title','phone','logo','likenum','paixu','readnum');
    $orderby='paixu desc';
	$total='';
	$return['list']=pdo_getslice('jy_cmso2o_list',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$v['lat_lng']=json_decode($v['lat_lng'],true);
		$v['juli']=cfc('tools')->getdistance($postdata['lat_lng']['lng'],$postdata['lat_lng']['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
		$v['juli']=intval($v['juli']/1000);
	}
	$_SESSION['o2olist']=$return['list'];
	
	if($postdata['keyword']!='juli'){
		
	}else{
		paixu($_SESSION['o2olist'],'juli','asc');
	}
	$return['list']=$_SESSION['o2olist'];
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择商户','error','/list/');
	}
	$return['detail']=pdo_get('jy_cmso2o_list',array('id'=>$id));
	$groupname=pdo_getcolumn('jy_cmso2o_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$return['detail']['group_id']),'title');
	$return['detail']['groupname']=$groupname;
	exi($return);
}
if($_RQ['op']=='comments'){
	$id=intval($_RQ['id']);
	if($id){
		exi('请选择商户','error','/list/');
	}
	$postdata=get_postdata();
	$data=array_fields(array('type','content'),$postdata);
	$data['uid']=$_SESSION['uid'];
	$data['uniacid']=$_SESSION['uniacid'];
	$data['cid']=$id;
	$data['status']=1;
	pdo_insert('jy_cmso2o_comments',$data);
	exi('评论成功','','/list/detail');
	}
if($_RQ['op']=='like'){
	$id=intval($_RQ['id']);
	if($id){
		exi('请选择商户','error','/list/');
	}
	$like=pdo_get('jy_cmso2o_like',array('uniacid'=>$_SESSION['uniacid'],'uid'=>$_SESSION['uniacid'],'cid'=>$id));
	if(empty($like)){
		$data=array('uniacid'=>$_SESSION['uniacid'],'uid'=>$_SESSION['uniacid'],'cid'=>$id);
		pdo_insert('jy_cmso2o_like',$data);
		exi('点赞成功','','/list/detail');
	}else{
		pdo_delete('jy_cmso2o_like',$data);
		exi('取消点赞成功','','/list/detail');
	}
	
	}
?>